package per.hnvcam.searchext.services.impl;

import per.hnvcam.searchext.services.CallbackSupportService;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Vi Cam
 * Date: 26/03/2012
 * Time: 23:38
 * To change this template use File | Settings | File Templates.
 */
public class CallbackSupportServiceImpl implements CallbackSupportService {
   private Map<String, Runnable> callbackActions;

   public CallbackSupportServiceImpl() {
      callbackActions = new HashMap<String, Runnable>();
   }

   @Override
   public void addCallbackAction(String name, Runnable action) {
      if (callbackActions == null) {
         callbackActions = new HashMap<String, Runnable>();
      }
      callbackActions.put(name, action);
   }

   @Override
   public void removeCallbackAction(String name) {
      if (callbackActions == null) {
         return;
      }
      callbackActions.remove(name);
   }

   @Override
   public void executeCallback() {
      for (Runnable action : callbackActions.values()) {
         action.run();
      }
   }
}
